<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\service\AdminService;
use app\admin\service\ConfigService;
use app\admin\service\MenuService;

class AdminApi extends AdminController
{
    public $noNeedPermission = ['getPermissionInfo'];
    
    /**
     * 获取后台权限信息
     *
     * @Author tanruizheng
     * @DateTime 2021-07-08
     * @return void
     */
    public function getPermissionInfo(){
        $adminInfo = AdminService::instance()->getAdminInfo();
        $menuInfo = MenuService::getAdminUserMenuTree($adminInfo['role_id']);
        //获取配置信息
        $config = ConfigService::getConfig()['data'];
        $menuList = [
            'homeInfo' => [
                'title' => '首页',
                'href' => url('Main/index', [], true, true)->__toString(),
            ],
            'logoInfo' => [
                'title' => $config['sitename'],
                'image' => $config['sitelogo'],
                'href' => '',
            ],
            'menuInfo' => [[
                'title' => '菜单管理',
                'href' => '',
                'icon' => 'fa fa-address-book',
                'target' => '_self',
                'child' => $menuInfo
            ]],
        ];
        return json($menuList);
    }
}
